/*
 * Trail.cpp
 *
 *  Created on: 2012/07/12
 *      Author: weihe
 */

#include "Trail.h"
#include <gl/glut.h>

namespace object {

Trail::~Trail() {
}

bool Trail::update(float dt) {
	static const float ALPHA_DECREASE_PER_SEC = 0.25;
	alpha -= ALPHA_DECREASE_PER_SEC * dt;
	if (alpha <= 0.01) {
		return false;
	}
	return true;
}

void Trail::draw() {
	Material smookeMat(Color4f(1, 1, 1, 0.4 * alpha));
	smookeMat.setupMaterial(GL_FRONT);
	glPushMatrix();
	{
		glTranslatef(position.x, position.y, position.z);
		static int id = -1;
		if (id == -1) {
			id = glGenLists(1);
			glNewList(id, GL_COMPILE_AND_EXECUTE);
			{
				glutSolidSphere(0.1, 8, 8);
			}
			glEndList();
		} else {
			glCallList(id);
		}
	}
	glPopMatrix();
}

} /* namespace object */
